from rest_framework.generics import ListAPIView, CreateAPIView
from users.models import User
from meiduo_admin.serializers.user_serializer import *
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from meiduo_admin.pages import MyPage



class UserAPIView(ListAPIView, CreateAPIView):
    queryset = User.objects.filter(is_staff=True)
    serializer_class = UserModelSerializer
    pagination_class = MyPage

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return self.queryset.filter(username__contains=keyword)
        return self.queryset.all()